import java.awt.Container;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.*;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import javax.swing.*;

public class MudarIp implements ActionListener {
	public static JTextField textField= new JTextField(20);
	public static JLabel ip = new JLabel();
	public static JButton mudarIp = new JButton("Salvar");		
	JFrame frame = new JFrame("Teste");
	GridBagConstraints c = new GridBagConstraints(); 
	GridBagLayout grid = new GridBagLayout();
	public MudarIp(){
		frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE); 
		frame.setBounds(30, 30, 300, 300);
		Container content = frame.getContentPane(); // Get the content pane
		content.setLayout(grid);// Set the container layout mgr
	    			//cria os botoes
		ip.setText("o ip do seu Android era : " + Client.ip);
		mudarIp.addActionListener(new Ip());
		c.gridx = 2;
	    c.gridy = 0;
		content.add(mudarIp,c);
		c.gridx = 1;
	    c.gridy = 1;
		content.add(ip,c);
		c.gridx = 0;
	    c.gridy = 0;
		content.add(textField,c);
		frame.pack();
	}
	public void actionPerformed (ActionEvent e){
		frame.setVisible(true);
	}
	
	private class Ip implements ActionListener{
		public void actionPerformed(ActionEvent e) {
			Client.ip = textField.getText();
		    	try {
		    		new File("Ip.txt").delete();
					FileWriter writer = new FileWriter("Ip.txt",true);
					writer.write(Client.ip);
					writer.close();
					
				} catch (IOException e1) {
					e1.printStackTrace();
				} 
			frame.dispose();
			
		}
		
	}
}
 